package com.vkserver;

import com.google.gwt.core.client.GWT;
import com.vkserver.services.utils.User;
import org.restlet.data.MediaType;
import org.restlet.data.Preference;
import org.restlet.resource.Result;


/**
 *@author roman.prudkogliad@gmail.com
 */
public class ServerClient {
    int serverPort;
    public String message;
    private Object lockObj = new Object();


    public ServerClient(int serverPort){
        this.serverPort = serverPort;
    }

    public boolean connect(){
        UserResourceProxy userResourceProxy = GWT.create(UserResourceProxy.class);
        userResourceProxy.getClientResource().setReference("http://localhost:8080/vkservice/user");
        userResourceProxy.getClientResource().getClientInfo().getAcceptedMediaTypes().add(new
                Preference<MediaType>(MediaType.APPLICATION_JAVA_OBJECT_GWT));
        userResourceProxy.retrieve(new Result<User>(){

            public void onFailure(Throwable throwable) {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            public void onSuccess(User user) {
                System.out.println("user " + user);
            }
        });

        return false;
    }

    public String tryMessage(String messageTo){

        return null;
    }

    private synchronized void waitReply(){
        synchronized (lockObj){
            try {
                lockObj.wait(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
        }
    }
}
